package arxivtests;


import static org.junit.Assert.*;

import java.net.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import arxiv.KeywordData;
import arxiv.SearchForm;
import arxiv.Query;

public class QueryTest {

	private SearchForm mySearchForm;
    private KeywordData mySearchData;
    private Query myQuery;

	@Before
	public void setUp() throws Exception {
		mySearchData = new KeywordData();
		mySearchForm = new SearchForm(mySearchData);
		myQuery = new Query(mySearchData, mySearchForm);
	}

	@After
	public void tearDown() throws Exception {
	}


    @Test
    public void testBuildQueryString() {
        String myQueryString = myQuery.buildQueryString();
        assertEquals(myQueryString, "http://export.arxiv.org/api/query?search_query=all:A sample keyword+au:A sample author+ti:A sample title&start=0&max_results=20");
    }

    @Test
    public void testbuildURL() throws MalformedURLException {
        // TODO: test cases with formatting
        URL myURL = myQuery.buildURL("http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=2");
        URL myURL2 = new URL("http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=2");
        assertEquals(myURL, myURL2);
    }

}
